﻿<%@ WebHandler Language="C#" Class="wxMiniProgramLogin" %>
using Models;
using System;
using System.Web;
using Newtonsoft.Json;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using System.Net;
using Newtonsoft.Json.Linq;


public class wxMiniProgramLogin : IHttpHandler {
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";



        string openid = context.Request.Headers["X-ACCESS-USER"];//Header中的token

        if (string.IsNullOrEmpty(openid))
        {
            HttpContext.Current.Response.Write("parameter error");
            return;
        }


        var msg = "默认收货地址";
        var time = DateTime.Now;

        using (Entities bll = new Entities())
        {

            var x = bll.S_UADDRESS.FirstOrDefault(p => p.Uopenid == openid);
            if (x != null)
            {
                var data = new
                {
                    id = x.UAID,
                    is_default = x.UAState,
                    name = x.UPeopleName,
                    phone = x.UAPhone,
                    province_name = x.UAProvance,
                    city_name = x.UACity,
                    area_name = x.UADistrict,
                    addr = x.UDetailAddress,
                     x.UAddName

                };

                context.Response.Write(JsonConvert.SerializeObject(new { code=1, msg, time, data }));

            }

            else
            { 
                   context.Response.Write(JsonConvert.SerializeObject(new { code=0, msg, time })); 
           }



        }

        HttpContext.Current.Response.End();
    }





    public bool IsReusable {
        get {
            return false;
        }
    }

}